package fr.emn.integration.synthese.controle;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JButton;
import fr.emn.integration.synthese.abstraction.Cours;

public class ControlJButtonDeleteEleve implements Observer, ActionListener {

	private Cours modele;
	private JButton button;

	public ControlJButtonDeleteEleve(Cours modele, JButton button) {
		this.modele = modele;
		this.button = button;
		button.setEnabled(false);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		try {
			modele.deleteEleve(modele.getEleveCourant());
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}

	@Override
	public void update(Observable o, Object message) {
		Integer iMessage = (Integer) message;
		if (iMessage == Cours.CHANGEMENT_ELEVES || iMessage == Cours.CHANGEMENT_ELEVE_COURANT) {
			if (modele.getEleveCourant() == -1)
				button.setEnabled(false);
			else
				button.setEnabled(true);
		}
	}
	
}
